package com.dv.web.controller.plan;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.poi.ExcelUtil;
import com.dv.driverless.domain.PlanDelivery;
import com.dv.driverless.service.IPlanDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出库计划Controller
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/plan/delivery")
public class PlanDeliveryController extends BaseController
{
    @Autowired
    private IPlanDeliveryService planDeliveryService;

    /**
     * 查询出库计划下发列表
     */
    @PreAuthorize("@ss.hasPermi('plan:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlanDelivery planDelivery)
    {
        startPage();
        List<PlanDelivery> list = planDeliveryService.selectPlanDeliveryList(planDelivery);
        return getDataTable(list);
    }

    /**
     * 导出出库计划下发列表
     */
    @PreAuthorize("@ss.hasPermi('plan:delivery:export')")
    @Log(title = "出库计划下发（", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanDelivery planDelivery)
    {
        List<PlanDelivery> list = planDeliveryService.selectPlanDeliveryList(planDelivery);
        ExcelUtil<PlanDelivery> util = new ExcelUtil<PlanDelivery>(PlanDelivery.class);
        util.exportExcel(response, list, "出库计划下发（数据");
    }

    /**
     * 获取出库计划下发详细信息
     */
    @PreAuthorize("@ss.hasPermi('plan:delivery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(planDeliveryService.selectPlanDeliveryById(id));
    }

    /**
     * 新增出库计划下发
     */
    @PreAuthorize("@ss.hasPermi('plan:delivery:add')")
    @Log(title = "出库计划下发（", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanDelivery planDelivery)
    {
        return toAjax(planDeliveryService.insertPlanDelivery(planDelivery));
    }

    /**
     * 修改出库计划下发
     */
    @PreAuthorize("@ss.hasPermi('plan:delivery:edit')")
    @Log(title = "出库计划下发（", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanDelivery planDelivery)
    {
        return toAjax(planDeliveryService.updatePlanDelivery(planDelivery));
    }

    /**
     * 删除出库计划下发（
     */
    @PreAuthorize("@ss.hasPermi('plan:delivery:remove')")
    @Log(title = "出库计划下发（", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planDeliveryService.deletePlanDeliveryByIds(ids));
    }
}

